#include <iostream>
#include <stdlib.h>
#include <string>

#define maxsize 10

using namespace std;

struct Cir_queue
{
    int data[maxsize];
    int rear;
    int front;
};

Cir_queue* init()
{
    Cir_queue* q=(Cir_queue* ) new Cir_queue;
    if(q==NULL)
    {
        exit(0);
    }
    memset (q->data,0,sizeof(q->data));
    q->front=0;
    q->rear=0;
    return q;
}

void push(Cir_queue* q,int data)
{
    if((q->rear+1)%maxsize==q->front)
    {
        cout<<"there are not enough story"<<endl;
        return ;
    }
    else
    {
        q->rear=(q->rear+1)%maxsize;
        q->data[q->rear]=data;
    }
}

void pop(Cir_queue* q)
{
    if(q->rear==q->front)
    {
        cout<<"this is an empty queue"<<endl;
        return;
    }
    else
    {
        q->data[q->front]=0;
        q->front=(q->front+1)%maxsize;
    }

}

void display(Cir_queue* q)
{
   int i=q->front;
    while(i!=q->rear)
    {
        i=(i+1)%maxsize;
        cout<<"  "<<q->data[i];
    }
    cout<<endl;
}

int main()
{
    Cir_queue* q=init();
    cout<<"enter into queue"<<endl;
    for(int i=0;i<6;i++)
    {
        push(q,i);
    }
    display(q);

    cout<<"exit the queue"<<endl;
    for(int i=0;i<3;i++)
    {
        pop(q);
        display(q);
    }

    system("pause");
    return 0;
}


